//
//  HNSH_TongZhengTopView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/5/26.
//

#import "HNSH_TongZhengTopView.h"

#import "HNSH_TZExchangeViewController.h"
#import "HNSH_TZRuZhangViewController.h"

@interface HNSH_TongZhengTopView ()

/* bgImgV */
@property (nonatomic, strong) UIImageView *bgImgV;
/* myDataButton */
@property (nonatomic, strong) UIButton *myDataButton;
/* bgTopImgV */
@property (nonatomic, strong) UIImageView *bgTopImgV;

/* 通证余额 */
@property (nonatomic, strong) UILabel *ztyeTitleLabel;
@property (nonatomic, strong) UILabel *ztyeLabel;

/* 待入账 */
@property (nonatomic, strong) UILabel *drzTitleLabel;
@property (nonatomic, strong) UILabel *drzLabel;

/* 已入账 */
@property (nonatomic, strong) UILabel *yrzTitleLabel;
@property (nonatomic, strong) UILabel *yrzLabel;

/* 兑换 */
@property (nonatomic, strong) UIButton *dhButton;

/* bottomImgV */
@property (nonatomic, strong) UIImageView *bottomImgV;

@end

@implementation HNSH_TongZhengTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#101010"];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_TongZhengModel *)model {
    _model = model;
    self.ztyeLabel.text = [NSString stringWithFormat:@"%.2f",[model.balance doubleValue]];
    self.drzLabel.text = [NSString stringWithFormat:@"%.2f",[model.left_value doubleValue]];
    self.yrzLabel.text = [NSString stringWithFormat:@"%.2f",[model.right_value doubleValue]];
}

- (void)configUI {
    [self addSubview:self.bgImgV];
    [self addSubview:self.bgTopImgV];
    [self.bgTopImgV addSubview:self.myDataButton];
    
    [self.bgTopImgV addSubview:self.ztyeTitleLabel];
    [self.bgTopImgV addSubview:self.ztyeLabel];
    
    [self.bgTopImgV addSubview:self.drzTitleLabel];
    [self.bgTopImgV addSubview:self.drzLabel];
    
    [self.bgTopImgV addSubview:self.yrzTitleLabel];
    [self.bgTopImgV addSubview:self.yrzLabel];
    
    [self.bgTopImgV addSubview:self.dhButton];
    
    [self addSubview:self.bottomImgV];
}

#pragma mark lazy
- (UIImageView *)bgImgV {
    if (!_bgImgV) {
        _bgImgV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 272)];
        _bgImgV.image = [UIImage imageNamed:@"tz_top_bg"];
    }
    return _bgImgV;
}

- (UIButton *)myDataButton {
    if (!_myDataButton) {
        _myDataButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _myDataButton.frame = CGRectMake(_bgTopImgV.width-150, 0, 150, 28);
    }
    return _myDataButton;
}

- (UIImageView *)bgTopImgV {
    if (!_bgTopImgV) {
        _bgTopImgV = [[UIImageView alloc]initWithFrame:CGRectMake(12, kNavBarAndStatusBarHeight+8, kScreenWidth-24, 176)];
        _bgTopImgV.image = [UIImage imageNamed:@"tz_top_left_bg"];
        _bgTopImgV.userInteractionEnabled = YES;
    }
    return _bgTopImgV;
}

- (UILabel *)ztyeTitleLabel {
    if (!_ztyeTitleLabel) {
        _ztyeTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 32, 200, 20)];
        _ztyeTitleLabel.text = @"通证余额";
        _ztyeTitleLabel.textColor = [UIColor colorWithHexString:@"#FFEDD6"];
        _ztyeTitleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _ztyeTitleLabel;
}

- (UILabel *)ztyeLabel {
    if (!_ztyeLabel) {
        _ztyeLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 53, 200, 40)];
        _ztyeLabel.text = @"0.00";
        _ztyeLabel.textColor = [UIColor appWhiteLabelColor];
        _ztyeLabel.font = [UIFont boldSystemFontOfSize:28];
    }
    return _ztyeLabel;
}


- (UILabel *)drzTitleLabel {
    if (!_drzTitleLabel) {
        _drzTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 113, 100, 17)];
        _drzTitleLabel.text = @"待入账";
        _drzTitleLabel.textColor = [UIColor colorWithHexString:@"#FFEDD6"];
        _drzTitleLabel.font = [UIFont systemFontOfSize:12];
        _drzTitleLabel.userInteractionEnabled = YES;
        WeakSelf(weakSelf);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            HNSH_TZRuZhangViewController *vc = [[HNSH_TZRuZhangViewController alloc]init];
            vc.status = @"10";
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
        [_drzTitleLabel addGestureRecognizer:tap];
    }
    return _drzTitleLabel;
}

- (UILabel *)drzLabel {
    if (!_drzLabel) {
        _drzLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 131, 100, 25)];
        _drzLabel.text = @"0.00";
        _drzLabel.textColor = [UIColor appWhiteLabelColor];
        _drzLabel.font = [UIFont boldSystemFontOfSize:18];
        _drzLabel.userInteractionEnabled = YES;
        WeakSelf(weakSelf);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            HNSH_TZRuZhangViewController *vc = [[HNSH_TZRuZhangViewController alloc]init];
            vc.status = @"10";
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
        [_drzLabel addGestureRecognizer:tap];
    }
    return _drzLabel;
}

- (UILabel *)yrzTitleLabel {
    if (!_yrzTitleLabel) {
        _yrzTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(138, 113, 100, 17)];
        _yrzTitleLabel.text = @"已入账";
        _yrzTitleLabel.textColor = [UIColor colorWithHexString:@"#FFEDD6"];
        _yrzTitleLabel.font = [UIFont systemFontOfSize:12];
        _yrzTitleLabel.userInteractionEnabled = YES;
        WeakSelf(weakSelf);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            HNSH_TZRuZhangViewController *vc = [[HNSH_TZRuZhangViewController alloc]init];
            vc.status = @"20";
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
        [_yrzTitleLabel addGestureRecognizer:tap];
    }
    return _yrzTitleLabel;
}

- (UILabel *)yrzLabel {
    if (!_yrzLabel) {
        _yrzLabel = [[UILabel alloc]initWithFrame:CGRectMake(138, 131, 100, 25)];
        _yrzLabel.text = @"0.00";
        _yrzLabel.textColor = [UIColor appWhiteLabelColor];
        _yrzLabel.font = [UIFont boldSystemFontOfSize:18];
        _yrzLabel.userInteractionEnabled = YES;
        WeakSelf(weakSelf);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            HNSH_TZRuZhangViewController *vc = [[HNSH_TZRuZhangViewController alloc]init];
            vc.status = @"20";
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
        [_yrzLabel addGestureRecognizer:tap];
    }
    return _yrzLabel;
}

- (UIButton *)dhButton {
    if (!_dhButton) {
        _dhButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _dhButton.frame = CGRectMake(self.bgTopImgV.width-90, 126, 70, 30);
        [_dhButton setImage:[UIImage imageNamed:@"tz_btn_duihuan"] forState:UIControlStateNormal];
        [[_dhButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            HNSH_TZExchangeViewController *vc = [[HNSH_TZExchangeViewController alloc]init];
            vc.type = 1;
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
    }
    return _dhButton;
}

- (UIImageView *)bottomImgV {
    if (!_bottomImgV) {
        _bottomImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tz_bottom_icon"]];
        _bottomImgV.frame = CGRectMake(12, kNavBarAndStatusBarHeight+220, kScreenWidth-24, 28);
    }
    return _bottomImgV;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
